package com.city.statisticsservice.scheduling;

import com.city.statisticsservice.service.StatisticsDailyService;
import com.city.statisticsservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: Cheng
 * Date: 2020/10/13
 * Time: 16:05
 * Description: No Description
 */
@Component
public class Scheduling {

    /*@Scheduled(cron = "0/5 * * * * ?")
    public void test(){
        System.out.println("使用springboot定时任务，通过cron设定自动执行的时间。。。");
    }*/

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    //每天凌晨一点自动执行注册数等前一天的数据库更新
    @Scheduled(cron ="0 0 1 * * ?")
    public void schedulingCount(){
        String s = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        statisticsDailyService.getCount(s);
    }
}
